<template>
  <div class="goodsBox">
    <template v-for="(item, index) in goodsList">
      <div
        :class="
          goodsShowType == 2
            ? 'goodItem1'
            : goodsShowType == 1
            ? 'goodItem2'
            : 'goodItem1'
        "
        :key="index"
        @click.stop="toGoods(item.id)"
        :style="{
          minWidth:
            goodsShowType == 1
              ? '100%'
              : goodsShowType == 2 && styleType == 8
              ? '326rpx'
              : '226rpx',
          width:
            goodsShowType == 1
              ? '100%'
              : goodsShowType == 2 && styleType == 8
              ? '326rpx'
              : '226rpx',
        }"
      >
        <div
          class="goodPic"
          :style="{
            minWidth:
              goodsShowType == 1
                ? '200rpx'
                : goodsShowType == 2 && styleType == 8
                ? '326rpx'
                : '226rpx',
            width:
              goodsShowType == 1
                ? '200rpx'
                : goodsShowType == 2 && styleType == 8
                ? '326rpx'
                : '226rpx',
            height:
              goodsShowType == 1
                ? '200rpx'
                : goodsShowType == 2 && styleType == 8
                ? '326rpx'
                : '226rpx',
            minHeight:
              goodsShowType == 1
                ? '200rpx'
                : goodsShowType == 2 && styleType == 8
                ? '326rpx'
                : '226rpx',
          }"
        >
          <image lazy-load :src="item.pic_url" />
          <goodsSaleNo :imgWidth="'132rpx'" :goodsInfo="item"></goodsSaleNo>
        </div>
        <div class="goodInfo">
          <span class="goodName">
            {{ item.name }}
          </span>
          <span class="goodCount">
            {{ $t("goods.count") }}{{ item.sales }}
          </span>
          <div class="price-box">
            <div class="price">
              <div class="new">
                <span>￥</span>
                <span>{{ item.price }}</span>
              </div>
              <div class="old" v-if="parseFloat(item.original_price)">
                {{ item.original_price }}
              </div>
            </div>
            <div
              class="buy-btn"
              @click.stop="toAddcart(item)"
              v-if="item.product_type == 0"
            >
              <i class="iconfont icon-add-select"></i>
            </div>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
import goodsSaleNo from "@/components/goodsSaleNo/index.vue";

export default {
  props: {
    propsData: {
      type: Object,
      default: {},
    },
    goodsList: {
      type: Array,
      default: [],
    },
  },
  mixins: [],
  components: {
    goodsSaleNo,
  },
  data() {
    return {
      good: {},
    };
  },
  mounted() {},
  watch: {},
  computed: {
    goodsShowType() {
      return this.propsData.params.goodsShowType;
    },
    styleType() {
      return this.propsData.params.styleType || "1";
    },
  },
  methods: {
    // 点击添加购物车
    toAddcart(e) {
      // this.good = JSON.parse(JSON.stringify(e));
      // setTimeout(() => {
      //   this.good = {};
      // }, 1);
      uni.$emit("diyAddGood", e);
    },
    // 跳转商品
    toGoods(id) {
      uni.navigateTo({
        url: "/goods/goods/goods?id=" + id,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.goodsBox {
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  .goodItem1 {
    margin-bottom: 20rpx;
    .goodPic {
      width: 100%;
      height: 226rpx;
      border-radius: 10rpx;
      overflow: hidden;
      position: relative;
      image {
        width: 100%;
        height: 100%;
        display: block;
      }
    }
    .goodInfo {
      // height: 100%;
      padding: 14rpx 0;
    }
  }
  .goodItem2 {
    width: 100%;
    display: flex;
    margin-bottom: 28rpx;
    .goodPic {
      width: 200rpx;
      height: 200rpx;
      min-width: 200rpx;
      border-radius: 10rpx;
      overflow: hidden;
      position: relative;
      image {
        width: 100%;
        height: 100%;
        display: block;
      }
    }
    .goodInfo {
      position: relative;
      height: 100%;
      padding-bottom: 28rpx;
      flex: auto;
      margin-left: 28rpx;
    }
    .goodInfo::before {
      position: absolute;
      bottom: 0px;
      right: -32rpx;
      content: "";
      width: calc(100% + 32rpx);
      height: 1px;
      background-color: #f5f6f7;
    }
  }
  .goodItem2:last-child {
    margin-bottom: 0;
  }
  .goodInfo {
    display: flex;
    flex-direction: column;
    .goodName {
      height: 80rpx;
      line-height: 40rpx;
      font-size: 28rpx;
      color: #262626;
      font-weight: 600;
      font-family: PingFang SC;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      word-break: break-all;
    }
    .goodCount {
      margin: 4rpx;
      font-size: 24rpx;
      color: #8c8c8c;
      font-family: PingFang SC;
    }
    .price-box {
      position: relative;
      display: flex;
      align-items: flex-end;
      flex-wrap: wrap;
      justify-content: space-between;
      .price {
        display: flex;
        flex-direction: column;
        height: 85rpx;
        .new {
          display: flex;
          align-items: baseline;
          color: #f0250e;
          font-weight: 600;
          font-family: PingFang SC;
          span:nth-child(1) {
            font-size: 24rpx;
          }
          span:nth-child(2) {
            font-size: 36rpx;
          }
        }
        .old {
          font-family: PingFang SC;
          font-size: 24rpx;
          text-decoration: line-through;
          color: #888;
          margin-left: 10rpx;
        }
      }
      .buy-btn {
        position: absolute;
        right: 0;
        bottom: 0;
        width: 42rpx;
        height: 42rpx;
        background: #f0250e;
        border-radius: 16rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
        margin-left: 20rpx;
        .iconfont {
          font-size: 38rpx;
          font-weight: 700;
          color: #ffffff;
        }
      }
    }
  }
}
.add-padding-top {
  padding-top: 28rpx;
}
</style>
